package com.syedu.day03;

import java.time.LocalDate;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Scanner;

/**
 * @Description 分支结构, 可以让代码在运行时产生不同的分支
 * 1. if else           条件必须是boolean类型,如果返回true,则代码运行,反之不运行
 * 2. switch case
 *
 * @createTime 2022/3/4 15:48
 * @author Administrator
 */
public class IfDemo {
    public static void main(String[] args) {
        LocalDate localDate = LocalDate.now();
        int week = localDate.getDayOfWeek().getValue();
        /**
         * 判断
         * 1.单用 if(){}
         * 2.if else 二选一
         * 3.if else if多个 else N选一
         */
        if (week == 1) {
            System.out.println("星期一");
        } else if (week == 2) {
            System.out.println("星期二");
        } else if (week == 3) {
            System.out.println("星期三");
        } else if (week == 4) {
            System.out.println("星期四");
        } else if (week == 5) {
            System.out.println("星期五");
        } else if (week == 6) {
            System.out.println("星期六");
        } else {
            System.out.println("星期天");
        }

        System.out.println("-----------------------------");

        /**
         * 1.if可以嵌套使用
         * 2.if语句如果只有一行代码,则对应的大括号可以省略(不推荐)
         */
        int score = 85;
        if (score >= 0 && score <= 100) {
            if (score < 60) {
                System.out.println("不及格");
            } else if (score < 70) {
                System.out.println("及格");
            } else if (score < 90) {
                System.out.println("良好");
            } else {
                System.out.println("优秀");
            }
        } else {
            System.err.println("分数不合法...");
        }

        System.out.println("-----------------------------");

        Scanner scanner = new Scanner(System.in);
        System.out.println("请您输入年份和月份:");
        int year = scanner.nextInt();
        int month = scanner.nextInt();
        if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
            System.out.println("31天.");
        } else if (month == 4 || month == 6 || month == 9 || month == 11) {
            System.out.println("30天.");
        } else {
            //判断是否是润年
            //1.自己写
            //if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0){

            //2.JDK老日期
            //if (new GregorianCalendar().isLeapYear(year)) {

            //3.JDK新日期
            if (LocalDate.of(year, month, 1).isLeapYear()) {
                System.out.println("29天.");
            } else {
                System.out.println("28天.");
            }
        }
    }
}
